Strict 
Import mojo
Import agfx

Class TPivot Extends TEntity
	
	
	Field offset:TVector2 
	
	'|--------------------------------------------------------------------------------
	'| Constructor
	'|--------------------------------------------------------------------------------
	Method New(n:String,x:Float=0, y:Float=0,w:Int=32,h:Int=32)
	
		Self.name = n
		Self.speed = 1.0
		Self.position.Set(x,y)	
		Self.size.Set(w,h)
		Self.visible = True
		Self.rotation = 0
		Self.radius = w/2
		Self.offset = New TVector2(0,0)
		Self.velocity = New TVector2(0,0)
		Self.collision.Set(Self.position,Self.size,Self.radius)
	End
	
	'|--------------------------------------------------------------------------------
	'| UPDATE
	'|--------------------------------------------------------------------------------
	Method Update:Void()	
		Self.collision.UpdateByCenter(Self.position)
	End Method
	
	'|--------------------------------------------------------------------------------
	'| DRAW (add inside OnRender)
	'|--------------------------------------------------------------------------------
	Method Draw:Void()
		If DEBUG
					SetColor 255, 255, 0
					
					' collision shape
					SetAlpha 0.15
					SetColor 255,255,255
					Self.collision.DebugDraw_Corners()
					
						
					SetAlpha 1
					' direction
					SetColor(0,255,0)
					DrawLine(	Self.position.x+Self.offset.x,
								Self.position.y+Self.offset.y,
								Self.position.x+Self.offset.x+Self.direction.x*32,
								Self.position.y+Self.offset.y+Self.direction.y*32)
					
					' center
					
					DrawCircle(	Self.position.x + Self.offset.x , 
								Self.position.y + Self.offset.y ,2)
					
					' inner circle
					SetAlpha 0.5
					SetColor(255,255,0)
					DrawCircle(	Self.position.x + Self.offset.x , Self.position.y + Self.offset.y ,Self.radius)
					SetColor(255,255,255)
					SetAlpha 1
					
					' collision radius
					SetColor(255,0,0)
					SetAlpha 0.5
					DrawCircle(	Self.position.x + Self.offset.x , Self.position.y + Self.offset.y ,Self.collision.radius)
					SetColor(255,255,255)
					SetAlpha 1
					
					' collision square
					
					
					Self.collision.DebugDraw_Corners()
					'SetAlpha 0.5
					'SetColor(255,0,0)
					'DrawRectOutline(Self.collision.A.x + Self.offset.x , Self.collision.A.y + Self.offset.y ,Self.collision.size.x,Self.collision.size.y)
					SetColor(255,255,255)
					SetAlpha 1
					
					'CONSOLE.fnt._DrawText("POS  :" + Self.position.ToString(),Self.position.x-Self.size.x/2,Self.position.y+Self.size.y)
					'CONSOLE.fnt._DrawText("DIR  :" + Self.direction.ToString(),Self.position.x-Self.size.x/2,Self.position.y+Self.size.y+10)
					'CONSOLE.fnt._DrawText("ANG  :" + FormatNumber(Self.rotation),Self.position.x-Self.size.x/2,Self.position.y+Self.size.y+20)
					'CONSOLE.fnt._DrawText("[" + Self.name+"]",Self.position.x-Self.size.x/2,Self.position.y+Self.size.y+30)
				EndIf
	End Method
	
End Class








